package com.forezp.datastruct;

/**
 * Created by forezp on 2017/12/5.
 */
public class MyStack<T> {

    private static class Node<U> {
        U data;
        Node<U> next;

        public Node(U data, Node<U> next) {
            this.data = data;
            this.next = next;
        }

        public Node() {
            this(null, null);
        }

        public boolean isEnd() {
            return data == null && next == null;
        }
    }

    private Node<T> top;//根节点不存储数据

    private int size;

    private int modeCount;

    public MyStack() {
        top = new Node();
    }

    public void push(T data) {
        modeCount++;
        size++;
        top = new Node(data, top);
    }

    public T pop() {
        if (top.isEnd()) {
            return null;
        }
        size--;
        modeCount++;

        T data = top.data;
        top = top.next;
        return data;
    }

}
